package com.stream;


import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class MainMethod {
    public static void main(String[] args) {
        List<Integer> intCollect = Stream.of(1, 2, 4, 3, 5)
                .collect(Collectors.toList());
        //静态方法引用
        List<Integer> collectSorted = intCollect.stream()
                .sorted(Integer::compareTo)
//                .sorted((a,b)->Integer.compare(a,b))
                .collect(Collectors.toList());
        System.out.println("collectSorted:"+collectSorted);
//        特定对象的方法的引用
        List<String> sCollectSorted = Stream.of("a", "s", "d", "f", "g")
                .sorted(String::compareTo)
//                .sorted((a,b)->a.compareTo(b))
                .collect(Collectors.toList());
        System.out.println("sCollectSorted"+sCollectSorted);
        // 构造方法引用
        List<String> collectList = Stream.generate(String::new)
//                .generate(()-> new String())
                .limit(10)
                .collect(Collectors.toList());
        System.out.println("collectList:"+collectList);

        String [] stringArray = {"芭芭拉","詹姆斯","玛丽","约翰",
        "Patricia","Robert","Michael","Linda"};
        Arrays.sort(stringArray,String :: compareToIgnoreCase);
        Arrays.sort(stringArray,(a,b)->a.compareToIgnoreCase(b));
    }
}
